Age Calculator using HTML, CSS, and JavaScript for Blogger

0

Age Calculator using HTML, CSS, and JavaScript for Blogger

Age Calculator


Make positive to store the HTML, CSS, and JavaScript code in separate archives named index.html, style.css, and script.js, respectively. Then, add these archives to your Blogger template.


When any individual enters their date of beginning and clicks the "Calculate" button, the script will calculate their age and show it on the page. 


Note: This is a basic example and may not handle all possible edge cases. You can enhance it further based on your requirements.


I hope this helps! Let me know if you have any further questions.



HTML:


<!DOCTYPE html>
<html>
   <head>
      <title>Age Calculator</title>
      <link rel="stylesheet" type="text/css" href="style.css">
   </head>
   <body>
      <div class="container">
         <h2>Age Calculator</h2>
         <input type="date" id="dob" placeholder="Enter your date of birth">
         <button onclick="calculateAge()">Calculate</button>
         <div id="result"></div>
      </div>
      <script src="script.js"></script>
   </body> 
</html> 


CSS:


.container {
  text-align: center;
  margin-top: 100px;
}
h2 {
  color: #333;
}
input[type="date"] {
  padding: 8px;
  border-radius: 4px;
  border: 1px solid #ccc;
}
button {
  padding: 10px 20px;
  margin-top: 10px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
#result {
  font-size: 18px;
  font-weight: bold;
  margin-top: 20px;
}
.container {
  text-align: center;
  margin-top: 100px;
  border: 1px solid #ccc;
  padding: 20px;
  border-radius: 4px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}



Javascript:

function calculateAge() {
var dob = document.getElementById('dob').value;
var today = new Date();
var birthDate = new Date(dob);
var age = today.getFullYear() - birthDate.getFullYear();
var monthDiff = today.getMonth() - birthDate.getMonth();
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
document.getElementById('result').innerHTML = 'Your age is ' + age;
}


Note: This is a primary instance and may additionally no longer cope with all viable facet cases. You can beautify it similarly based totally on your requirements. I hope this helps! Let me comprehend if you have any in addition questions.


Age calculator images free Age calculator images by date of birth Age calculator images free download face age calculator age a photo online face age

Post a Comment

0 Comments
Post a Comment (0)